package com.sky.controller.user;

import com.sky.Service.SetmealService;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "用户-套餐管理")
@RestController(value = "userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据id获取套餐列表
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames="setmealCache",key="#categoryId")
    @ApiOperation("根据id获取套餐列表")
    @GetMapping("/list")
    public Result<List<Setmeal>> getSetmealListById(Long categoryId) {
        System.out.println("categoryId:" + categoryId);
        List<Setmeal> setmealList = setmealService.getSetmealListById(categoryId);
        return Result.success(setmealList);
    }


    /**
     * 根据套餐id来获取套餐所包含菜品列表，并缓存
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id来获取套餐所包含菜品列表")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishesByCategoryId(@PathVariable Long id) {
        System.out.println("id:" + id);
        List<DishItemVO> dishesByCategoryId = setmealService.getDishesByCategoryId(id);
        return Result.success(dishesByCategoryId);
    }
}
